package com.itheima.api.homework;

import java.math.BigDecimal;

/**
 * 题目二
 * 有以下学员信息：
 * 张三,男,20,79.5
 * 李四,女,21,80.2
 * 王五,男,22,77.9
 * 周六,男,20,55.8
 * 赵七,女,21,99.9
 * 请定义学员类，属性：姓名、性别、年龄、分数
 * 请编写测试类，创建5个对象，分别存储上述值，并计算5名学员的“平均分”(四舍五入到小数点后2位)。
 */
public class Test2 {
    public static void main(String[] args) {
        //创建5个学生对象
        Student s1 = new Student("张三", "男", 20, 79.5);
        Student s2 = new Student("李四", "女", 21, 80.2);
        Student s3 = new Student("王五", "男", 22, 77.9);
        Student s4 = new Student("周六", "男", 20, 55.8);
        Student s5 = new Student("赵七", "女", 21, 99.9);
        //求和
        BigDecimal sum = new BigDecimal("0");
        sum = sum.add(BigDecimal.valueOf(s1.getScore()));
        sum = sum.add(BigDecimal.valueOf(s2.getScore()));
        sum = sum.add(BigDecimal.valueOf(s3.getScore()));
        sum = sum.add(BigDecimal.valueOf(s4.getScore()));
        sum = sum.add(BigDecimal.valueOf(s5.getScore()));
        //求avg
        BigDecimal avg = sum.divide(BigDecimal.valueOf(5), 2, BigDecimal.ROUND_HALF_UP);
        System.out.println("平均分为:" + avg.doubleValue());
    }
}

 class Student {
    private String name;
    private String sex;
    private int age;
    private double score;

    public Student() {
    }

    public Student(String name, String sex, int age, double score) {
        this.name = name;
        this.sex = sex;
        this.age = age;
        this.score = score;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public double getScore() {
        return score;
    }

    public void setScore(double score) {
        this.score = score;
    }
}